<script>

$.fn.shuffle = function() {
	return this.each(function(){
		var items = $(this).children();

		return (items.length)
			? $(this).html($.shuffle(items,$(this)))
		: this;
	});
}

$.fn.validate = function() {
	var res = false;
	this.each(function(){
		var arr = $(this).children();
		res =	((arr[0].innerHTML=="1")&&
			(arr[1].innerHTML=="2")&&
			(arr[2].innerHTML=="3")&&
			(arr[3].innerHTML=="4")&&
			(arr[4].innerHTML=="5")&&
			(arr[5].innerHTML=="6"));
	});
	return res;
}

$.shuffle = function(arr,obj) {
	for(
	var j, x, i = arr.length; i;
	j = parseInt(Math.random() * i),
	x = arr[--i], arr[i] = arr[j], arr[j] = x
);
	if(arr[0].innerHTML=="1") obj.html($.shuffle(arr,obj))
	else return arr;
}

$("#sortable").sortable();
$("#sortable").disableSelection();
$('#sortable').shuffle();

function test_captcha()
{
	if ($('#sortable').validate()) {
		gbfrm.mode.value="write";
		$(".captchaerr").text("");
		return true;
	}
	$(".captchaerr").text("{{!captcha_error}}");
	return false;
}

//generic_site_form_init("#guestbook-form");

function gbfrm_check()
{
	var flag=generic_site_form_check("#guestbook-form");
	return flag;
}

</script>
